<?php
    require_once('header_sidebar.php');
    require_once("Class/evaluation.Class.php");
    require_once('Class/connexionDB.Class.php');
    require_once('Class/search.Class.php');
    require_once('Class/displayInHtml.Class.php');

    $eval           = new evaluation();
    $db             = new connexionDB();
        
    $topics         = $eval->listedTopic();
    $form           = $db->getEvaluationForm();
    $consultant     = $db->getAllConsultant();
    $team           = $db->getTeam();
    $name_rater     = $db->getNameRater();
    $recipient      = $db->getRecipient();
?>
            <link rel="stylesheet" href="js/plugins/chosen/chosen.min.css">
            <!-- Right side column. Contains the navbar and content of the page -->
            <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        <?php echo $translate->translate('HomePageSearchRating'); ?>
                    </h1>
                    <ol class="breadcrumb">
                        <li><i class="fa fa-dashboard"></i> <?php echo $translate->translate('HomePageRating'); ?></li>
                        <li class="active"><?php echo $translate->translate('HomePageSearchRating'); ?></li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                	<div class="col-md-12 box box-info">
                        <form id="" action="" method="post">
                            <div class="box-body">
                                <div class="col-md-12">
                                    <h4 class="box-title">
                                        <?php echo $translate->translate('TitleReference'); ?>
                                    </h4>
                                </div>
                                <div class='row'>
                                    <div class="col-md-3">
                                        <div id="n_rating_div" class="form-group">
                                            <label><?php echo $translate->translate('NRating'); ?> :</label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-tag"></i>
                                                </div>
                                                <input id="n_rating" name="n_rating" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div id="n_order_div" class="form-group">
                                            <label><?php echo $translate->translate('NOrder'); ?> :</label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-barcode"></i>
                                                </div>
                                                <input id="n_order" name="n_order" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div id="n_akio_div" class="form-group">
                                            <label><?php echo $translate->translate('NAkio'); ?> :</label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-laptop"></i>
                                                </div>
                                                <input id="n_akio" name="n_akio" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
    		                    	<div class="col-md-4">
    		                            <!-- Date range -->
    		                            <div class="form-group">
    		                                <label><?php echo $translate->translate('DateEvaluation'); ?> :</label>
    		                                <div class="input-group">
    		                                    <div class="input-group-addon">
    		                                        <i class="fa fa-calendar"></i>
    		                                    </div>
    		                                    <input type="text" class="form-control pull-right" name="ratingDate" id="reservation"/>
    		                                </div><!-- /.input group -->
    		                            </div><!-- /.form group -->
    		                        </div><!-- /.box -->
                                    <div class="col-md-4">
                                        <div id="account_type_div" class="form-group">
                                            <label><?php echo $translate->translate('EvaluationType'); ?> :</label><br>
                                            <input id="eval_type" name="eval_type" type="radio" class="form-control" value="junior"> Junior
                                            <input id="eval_type" name="eval_type" type="radio" class="form-control" value="senior"> Senior
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div id="min_mark_div" class="form-group">
                                            <label><?php echo $translate->translate('MarkMin'); ?> :</label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <div class="fa fa-pencil-square-o"></div>
                                                </div>
                                                <input id="min_mark" name="min_mark" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class="col-md-2">
                                        <div id="max_mark_div" class="form-group">
                                            <label><?php echo $translate->translate('MarkMax'); ?> :</label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-pencil-square-o"></i>
                                                </div>
                                                <input id="max_mark" name="max_mark" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div id="improvement" class="form-group">
                                            <label><?php echo $translate->translate('Improvement'); ?></label>
                                            <div class="input-group">
                                                <div class="input-group-addon">
                                                    <i class="fa fa-book"></i>
                                                </div>
                                                <input id="improvement" name="improvement" type="text" class="form-control">
                                            </div>
                                        </div>
                                    </div>
    		                        <div class="col-md-4">
                                        <div id="name_rater_div" class="form-group">
                                            <label><?php echo $translate->translate('NameRater'); ?> :</label>
                                            <div class="input-group">
                                                <select id="name_rater" name="name_rater" class="form-group chosen-select">
                                                    <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                    <?php foreach ($name_rater as $value) : ?>
                                                        <option value="<?php echo $value['name_rater']; ?>"><?php echo $value['name_rater']; ?></option>
                                                    <?php endforeach;?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class='row'>
                                    <div class="col-md-2">
                                        <div id="team_div" class="form-group">
                                            <label><?php echo $translate->translate('team'); ?> :</label>
                                            <div class="input-group">
                                                <select id="team" name="team" class="form-group chosen-select" >
                                                    <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                    <?php foreach ($team as $value) : ?>
                                                        <option value="<?php echo $value['team']; ?>"><?php echo $value['team']; ?></option>
                                                    <?php endforeach;?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div id="name_consultant_div" class="form-group">
                                            <label><?php echo $translate->translate('Consultant'); ?> :</label>
                                            <div class="input-group">
                                                <select id="name_consultant" name="name_consultant" class="form-group chosen-select" >
                                                    <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                    <?php foreach ($consultant as $value) : ?>
                                                        <option value="<?php echo $value['name']; ?>"><?php echo $value['name']; ?></option>
                                                    <?php endforeach;?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div id="topic" class="form-group">
                                            <div class="box-body">
                                                <label for="list_topic"><?php echo $translate->translate('DescriptionListTopic'); ?></label>
                                                <div id="list_topic" class="box-content form-group">
                                                    <select id="topic" name="topic" class="form-control chosen-select">
                                                        <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                        <?php 
                                                            foreach ($topics as $key => $value)
                                                            {
                                                                echo "<option value='".$value['id']."'>". $value['name'] ."</option>";
                                                            }
                                                        ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div id="topic" class="form-group">
                                            <div class="box-body">
                                                <?php 
                                                    $country = $db->getCountry();
                                                ?>
                                                <label for="list_topic"><?php echo $translate->translate('AdminNewAccountAccountCountry'); ?></label>
                                                <div id="list_country" class="box-content form-group">
                                                    <select id="country" name="country" class="form-control chosen-select" >
                                                        <option selected disabled ><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                        <?php 
                                                            foreach ($country as $key => $value)
                                                            {
                                                                echo "<option value='".$value['id']."'>". $value['name'] ."</option>";
                                                            }
                                                        ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div id="topic" class="form-group">
                                            <div class="box-body">
                                                <label for="list_topic"><?php echo $translate->translate('Recipient'); ?></label>
                                                <div id="list_recipient" class="box-content form-group">
                                                    <select id="recipient" name="recipient" class="form-control chosen-select" >
                                                        <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                        <?php 
                                                            foreach ($recipient as $key => $value)
                                                            {
                                                                echo "<option value='".$value['id']."'>". $value['name'] ."</option>";
                                                            }
                                                        ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div id="id_form_div" class="form-group">
                                            <label><?php echo $translate->translate('nameEval'); ?> :</label><br>
                                            <div id="list_form" class="box-content form-group">
                                                <select id="id_form" name="id_form" class="form-group chosen-select" >
                                                    <option selected disabled><?php echo $translate->translate('TitleSelectEvaluationDefault'); ?></option>
                                                    <?php foreach ($form as $value) : ?>
                                                        <option value="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></option>
                                                    <?php endforeach;?>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-10">
                                        <div id="groups" class="col-md-2">
                                            <label><?php echo $translate->translate('AdminNewAccountAccountGroup');?> :</label>
                                        </div>
                                        <div class="col-md-8">
                                            <?php
                                                $groups = $db->getListedGroup();
                                                echo displayInHtml::getCheckboxListFromArray($groups);
                                            ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-2 col-md-offset-8" style="margin:20px;">
                                    <button id="submitBtn" type="submit" class="btn btn-primary"><?php echo $translate->translate('HomePageSearchRating'); ?></button>
                                </div>
	                        </div>
                        </form>
                	</div><!-- /.row -->
                    <?php if (isset($_POST) && !empty($_POST)) : ?>
                        <?php 
                            $db = new connexionDB();
                            $search = new search();

                            $search->validateData($_POST);
                            $query = $search->generateQuery();
                            $result = $db->executeQuery($query);
                        ?>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="box">
                                    <div class="box-header">
                                        <h3 class="box-title">Résultats</h3>
                                    </div><!-- /.box-header -->
                                    <div class="box-body table-responsive">
                                        <table id="result_table" class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th><?php echo $translate->translate('NRating'); ?></th>
                                                    <th><?php echo $translate->translate('NOrder'); ?></th>
                                                    <th><?php echo $translate->translate('NAkio'); ?></th>
                                                    <th><?php echo $translate->translate('DateEvaluation'); ?></th>
                                                    <th><?php echo $translate->translate('NameRater'); ?></th>
                                                    <th><?php echo $translate->translate('Consultant'); ?></th>
                                                    <th><?php echo $translate->translate('finalMark'); ?></th>
                                                    <th><?php echo $translate->translate('Improvement'); ?></th>
                                                    <th><?php echo $translate->translate('team'); ?></th>
                                                    <th><?php echo $translate->translate('NameTopic'); ?></th>
                                                    <th><?php echo $translate->translate('AdminNewAccountAccountCountry'); ?></th>
                                                    <th><?php echo $translate->translate('AdminNewAccountAccountGroup');?></th>
                                                    <th><?php echo $translate->translate('EvaluationType'); ?></th>
                                                    <th><?php echo $translate->translate('Recipient'); ?></th>
                                                    <th><?php echo $translate->translate('nameEval'); ?></th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php 
                                                    foreach ($result as $key => $value)
                                                    {
                                                        echo '<tr style="cursor: pointer;" onclick="sendForm('. $value['id'] .');">';
                                                        foreach ($value as $keyb => $valueb)
                                                        {
                                                            echo '<td>' . $valueb  . '</td>';
                                                        }
                                                        echo '</tr>';
                                                    }
                                                ?>
                                            </tbody>
                                        </table>
                                    </div><!-- /.box-body -->
                                </div><!-- /.box -->
                            </div>
                        </div>
                    <?php endif ?>
                </section><!-- /.content -->
                <!-- Main content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->
        <?php require_once('footer.php'); ?>
        <!-- DATA TABES SCRIPT -->
        <script src="js/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
        <script src="js/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
        <!-- page script -->
        <!-- Chosen pluggin -->
        <script src="js/plugins/chosen/chosen.jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                $("#result_table").dataTable();
                $('#reservation').daterangepicker({
                    format: 'YYYY/MM/DD'
                });
            });

            function sendForm(id)
            {
                var old = window.location.href;
                var res = old.split('/');
                res[(res.length - 1)] = 'show_rating.php?id=' + id;
                var url = res.join('/');
                window.open(url, '_blank');
            }
        </script>
        <script type="text/javascript">
    var config = {
      '.chosen-select'           : {}
    }
    for (var selector in config) {
      $(selector).chosen(config[selector]);
    }
</script>